#define _CRT_SECURE_NO_WARNINGS 1

https://leetcode.cn/problems/sliding-window-maximum/description/

class Solution {
public:
    vector<int> maxSlidingWindow(vector<int>& nums, int k) {

        vector<int> q(nums.size());
        vector<int> ans;

        int hh = 0, tt = -1;

        for (int i = 0; i < nums.size(); i++)
        {
            if (hh <= tt && i - k + 1 > q[hh]) hh++;

            while (hh <= tt && nums[q[tt]] <= nums[i]) tt--;
            q[++tt] = i;

            if (i >= k - 1)
                ans.push_back(nums[q[hh]]);
        }
        return ans;
    }
};